package com.ge.mythreed.controller;

import com.ge.mytestparent.dto.Result;
import com.ge.mythreed.entity.GoodsInfo;
import com.ge.mythreed.service.GoodsInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author geqingxiang
 * @PackageName myProject
 * @Package com.example.myproject.controller
 * @Date 2023/4/18 13:46
 * @Version 1.0
 */
@Tag(name = "Kafka自测接口", description = "描述")
@RestController
@RequestMapping("test")
public class KafkaTestController {

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;
    @Autowired
    private GoodsInfoService goodsInfoService;

    @Operation(summary = "测试")
    @GetMapping("/test")
    public Result<?> get(@Parameter(name = "message", description = "数据ID") String message) {
        kafkaTemplate.send("sb_topic", message);
//        kafkaTemplate.send("canalKafkaTopicUserCenter", message);
        return Result.success("成功");
    }


    @Operation(summary = "创建数据")
    @GetMapping("/save")
    public Result<?> save() {
        GoodsInfo goodsInfo = new GoodsInfo();
        goodsInfo.setName("测试");
        goodsInfo.setType("商品");
        goodsInfo.setCreateDate(new Date());
        goodsInfo.setUpdateDate(new Date());
        goodsInfoService.save(goodsInfo);
        return Result.success("成功");
    }

}
